# -*- coding: utf-8 -*-

"""
@File    : 02_栅格HDF文件展示.py
@Author  : fungis@163.com
@notice  :
"""
import matplotlib.pylab as plt  # 画图模块
from osgeo import gdal, gdalconst

raster_path = r'./data-use/hdf/MOSAIC_TMP_2019273.hdf'  # 输入你的hdf文件
# raster_path = r'E:\ModisTools\Data_Mod14a1\Result\MOSAIC_TMP_2019249.hdf'  # 输入你的hdf文件(绝对路径)

dataset = gdal.Open(raster_path, gdalconst.GA_ReadOnly)  # 读取遥感数据信息
band = dataset.GetRasterBand(1)
location_array = band.ReadAsArray()  # 二维行列像元矩阵
plt.title('gdal-hdf-show')  # 设置图框标题为gdal-hdf-show
plt.imshow(location_array, cmap='rainbow')  # 绘图，配色为rainbow
plt.colorbar()  # 绘制图例
plt.savefig("./results/20220917.04.png", dpi=300)
plt.show()
